#include "StdAfx.h"
#include "Canvas.h"

CCanvas::CCanvas()
: ScreenWidth (0)
, ScreenHeight (0)
, ScreenData (0)
{
}
CCanvas::CCanvas(int width, int height)
: ScreenWidth (width)
, ScreenHeight (height)
{
	ScreenData = new float[ScreenWidth*ScreenHeight*3];
	Reset();
}
CCanvas::~CCanvas(void)
{
	delete[] ScreenData;
}
int CCanvas::GetScreenWidth()
{
	return ScreenWidth;
}
int CCanvas::GetScreenHeight()
{
	return ScreenHeight;
}
float* CCanvas::GetScreenData()
{
	return ScreenData;
}
void CCanvas::Reset()
{
	memset(ScreenData,0,ScreenWidth*ScreenHeight*3*sizeof(float));
}
unsigned char* CCanvas::GetImageData()
{
	unsigned char* data = new unsigned char[ScreenWidth*ScreenHeight*3];
	
	float exposure = 1.f; 
	for (int i=0;i<ScreenHeight;++i)
		for (int j=0;j<ScreenWidth;++j)
		{
			int offset = (i*ScreenWidth+j)*3;
			data[offset + 0] = (int)(255.f * ( 1 - exp(-ScreenData[offset + 2] * exposure)));
			data[offset + 1] = (int)(255.f * ( 1 - exp(-ScreenData[offset + 1] * exposure)));
			data[offset + 2] = (int)(255.f * ( 1 - exp(-ScreenData[offset + 0] * exposure)));
		}
	return data;
}